const form = document.querySelector('form')
const pwdInp = document.querySelector('.password')
const rpwdInp = document.querySelector('.rpassword')
const nameInp = document.querySelector('.nickname')
const useInp = document.querySelector('.username')

form.addEventListener('submit',e =>{
    e = e || window.event
    try{e.preventDefault()} catch(err) {e.returnValue = false}
    const info = {
        username:useInp.value,
        password:pwdInp.value,
        rpassword:rpwdInp.value,
        nickname:nameInp.value
    }
    if(!info.password || !info.username || !info.rpassword || !info.nickname){
      return layer.alert('请完整填写表单', {
          skin: 'layui-layer-lan'
          ,closeBtn: 0
          ,anim: 1//动画类型
        });
  }
    if(info.password !== info.rpassword)   return layer.msg('两次输入密码不一致')
    
    ajax({
        url:'http://localhost:8888/users/register',
      data: querystringify(info),
      method:'POST',
      dataType:'json',
      success(res){
        if(res.code === 0){
          layer.msg('注册失败');
        }
        if(res.code ===1){
          layer.confirm('注册成功，您是否跳转登录页？', {
            btn: ['确定','留在当前页面'] //按钮
          }, function(){
            window.location.href = './login.html'
          }, function(){
          });
        }
      }
    })
    
       
   


}
)































